#!/usr/bin/env perl
use warnings;
use strict;

my $x_px = 600;
my $y_px = 400;

sub plot_xy {
  my ($x_file, $x_col, $x_label,
      $y_file, $y_col, $y_label,
      $axis_bounds, $samples, $out_file) = @_;

  # Subsample files first. Then plot subsampled data.
  my $x_sub = "$x_file.subsample_$samples";
  my $y_sub = "$y_file.subsample_$samples";
  my $script = "plot_xy('\$(PWD)/$x_sub',$x_col,'$x_label',$x_px,".
                       "'\$(PWD)/$y_sub',$y_col,'$y_label',$y_px,".
                       "$axis_bounds,'\$(PWD)/$out_file')";
  print <<CMD;
$out_file: $x_file $y_file
\tperl src/subsample.pl $samples \`cat $x_file | wc -l\` "<$x_file" ">$x_sub" "<$y_file" ">$y_sub"
\tcd src; matlab -nojvm -nodisplay -r "$script;exit"; cd ..
\trm -f $x_sub $y_sub
CMD
}

plot_xy(
  'num_ratings_per_probe_movie.txt',2,'ratings_per_movie',
  'base_residuals.pred.errors.by_movie',6,'RMSE_*_num_probe_ratings',
  '[]',                       # axis bounds
  5000,                       # number of points to plot
  'base_residuals_ratings_probe_weighted_v_rmse_by_movie.eps');

plot_xy(
  'num_ratings_per_probe_movie.txt',2,'ratings_per_movie',
  'knnMovieResidualProbePredictionk_50_effects_26.pred.errors.by_movie',6,'RMSE_*_num_probe_ratings',
  '[]',                       # axis bounds
  5000,                       # number of points to plot
  'knnMovie_ratings_v_probe_weighted_rmse_by_movie.eps');

# Copyright (c) 2009 John Lees-Miller
# 
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

